package com.inossem.warehousestorage_inossem.utils;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.inossem.utils.base.Utils;
import com.inossem.utils.listener.NoDoubleClickListener;
import com.inossem.utils.log.LogUtils;
import com.inossem.warehousestorage_inossem.R;
import com.inossem.warehousestorage_inossem.activity.in_storage.InStorageReceiveMaterielDetailActivity;
import com.inossem.warehousestorage_inossem.activity.in_storage.chuangyou.CYInStorageProductionCompleteMaterielDetailActivity;
import com.inossem.warehousestorage_inossem.activity.in_storage.chuangyou.CYInStorageProductionListActivity;
import com.inossem.warehousestorage_inossem.activity.in_storage.chuangyou.CYInStorageShoppingDetailActivity;
import com.inossem.warehousestorage_inossem.adapter.inStorage.chuangyou.CYInStorageProductionCompleteMaterielDetailAdapter;
import com.inossem.warehousestorage_inossem.bean.inStorage.InStorageAllocatingGetListRequestBean;
import com.inossem.warehousestorage_inossem.bean.inStorage.InStorageAllocatingOverviewBean;
import com.inossem.warehousestorage_inossem.bean.inStorage.InStorageOtherBean;
import com.inossem.warehousestorage_inossem.bean.inStorage.chuangyou.CYInStorageCheckPositionRequestBean;
import com.inossem.warehousestorage_inossem.bean.inStorage.chuangyou.CYInStorageCheckSNCodeRequestBean;
import com.inossem.warehousestorage_inossem.bean.inStorage.chuangyou.CYInStoragePositionInformationBean;
import com.inossem.warehousestorage_inossem.bean.inStorage.chuangyou.CYInStorageProductionListBean;
import com.inossem.warehousestorage_inossem.bean.inStorage.chuangyou.CYInStorageProductionListRequestBean;
import com.inossem.warehousestorage_inossem.bean.inStorage.chuangyou.CYInStorageProductionOverviewBean;
import com.inossem.warehousestorage_inossem.bean.inStorage.chuangyou.CYInStorageProductionSubmitRequestBean;
import com.inossem.warehousestorage_inossem.bean.inStorage.chuangyou.CYInStorageShoppingConfirmRequestBean;
import com.inossem.warehousestorage_inossem.bean.inStorage.chuangyou.CYInStorageShoppingListRequestBean;
import com.inossem.warehousestorage_inossem.bean.inStorage.chuangyou.CYInStorageShoppingOverviewBean;
import com.inossem.warehousestorage_inossem.bean.inStorage.chuangyou.CYInStorageStringBean;
import com.inossem.warehousestorage_inossem.bean.outStorage.SNBean;
import com.inossem.warehousestorage_inossem.bean.outStorage.SNItemInfo;
import com.inossem.warehousestorage_inossem.dialog.DialogUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * TODO
 *
 * @author 王斯宇
 * @time on 2018/3/28 9:52
 * @email siyu.wang@inossem.com
 */
public class CYInStorageUtils {

    public static void createEditText(Context context, ViewGroup viewGroup,String positionCode , String text,String unitText , int id , CYInStorageShoppingDetailActivity.CYInStorageShoppingDetailListener listener) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.cy_view_in_storage_edittext, null);
        view.setId(id);
        TextView position = (TextView) view.findViewById(R.id.position);
        TextView unit = (TextView) view.findViewById(R.id.unit);
        view.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                DialogUtils.getConfirmDialog(context, "是否删除？", new DialogUtils.ConfirmDialogListener() {
                    @Override
                    public void onConfirm(Dialog dialog) {
                        dialog.dismiss();
                        listener.deleteClickListener(view.getId() , position.getText().toString());
                    }
                }).show();

                return false;
            }
        });
        unit.setText(unitText);
        EditText textEditText = (EditText) view.findViewById(R.id.text);
        position.setText(positionCode);
        textEditText.setText(text);
        viewGroup.addView(view);
    }

    public static void createPackagingCode(Context context, ViewGroup viewGroup,String status ,String codes , int id , CYInStorageProductionCompleteMaterielDetailActivity.InStorageMaterielListener listener) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.cy_view_change_storage_package_code, null);
        view.setId(id);
        ImageView image = (ImageView) view.findViewById(R.id.image);
        TextView name = (TextView) view.findViewById(R.id.name);
        TextView code = (TextView) view.findViewById(R.id.code);
        view.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                DialogUtils.getConfirmDialog(context, "是否删除？", new DialogUtils.ConfirmDialogListener() {
                    @Override
                    public void onConfirm(Dialog dialog) {
                        dialog.dismiss();
                        listener.onDeleteClickListener(view.getId() , code.getText().toString());
                    }
                }).show();

                return false;
            }
        });
        if (status.equals(CYInStorageProductionCompleteMaterielDetailActivity.PACKAGING_CODE)) {
            image.setBackgroundResource(R.drawable.ico_arrow3_down);
            name.setText("打包码");
            code.setText(codes);
            code.setTextColor(context.getResources().getColor(R.color.activity_receive_delivery_overview_font_color));
            view.setOnClickListener(new NoDoubleClickListener() {
                @Override
                public void onNoDoubleClick(View v) {
                    listener.onNoDoubleClickListener(code.getText().toString());
                }
            });
        }else if (status.equals(CYInStorageProductionCompleteMaterielDetailActivity.SERIAL_NUMBER)) {
            image.setBackgroundResource(R.drawable.ico_arrow3_down);
            name.setText("序列号");
            code.setText(codes);
        }
        viewGroup.addView(view);
    }

    //拼接获取采购单列表请求bean
    public static CYInStorageShoppingListRequestBean getShoppingGetListRequestBean(String condition) {
        CYInStorageShoppingListRequestBean bean = new CYInStorageShoppingListRequestBean();
        bean.setPurchase_order_code(condition);
        bean.setPage_index("1");
        bean.setPage_size("1");
        bean.setTotal("1");
        return bean;
    }
    //拼接获取生产入库列表请求bean
    public static CYInStorageProductionListRequestBean getProductionGetListRequestBean(String condition) {
        CYInStorageProductionListRequestBean bean = new CYInStorageProductionListRequestBean();
        bean.setProduction_order_code(condition);
        bean.setPage_index("1");
        bean.setPage_size("1");
        bean.setTotal("1");
        return bean;
    }
    //获取采购入库信息
    public static CYInStorageShoppingOverviewBean getInStorageShoppingOverviewBean(Context context) {
        String json = SPUtils.getInStorageShoppingOverViewlList(context);
        Gson gson = new Gson();
        return gson.fromJson(json, CYInStorageShoppingOverviewBean.class);
    }

    //获取生产入库信息
    public static CYInStorageProductionOverviewBean getInStorageProductionOverviewBean(Context context) {
        String json = SPUtils.getInStorageProductionOverViewlList(context);
        Gson gson = new Gson();
        return gson.fromJson(json, CYInStorageProductionOverviewBean.class);
    }
    //保存采购入库信息
    public static void saveInStorageShoppingOverViewBean (Context context , CYInStorageShoppingOverviewBean bean) {
        Gson gson = new Gson();
        SPUtils.saveInStorageShoppingOverViewlList(context, gson.toJson(bean, CYInStorageShoppingOverviewBean.class));
    }
    //保存生产入库信息
    public static void saveInStorageProductionOverViewBean (Context context , CYInStorageProductionOverviewBean bean) {
        Gson gson = new Gson();
        SPUtils.saveInStorageProductionOverViewlList(context, gson.toJson(bean, CYInStorageProductionOverviewBean.class));
    }
    //过滤采购入库货品列表信息
    public static List<CYInStorageShoppingOverviewBean.ItemBean.ItemListBean> getShoppingInStorageList(Context context, String materiel) {
        List<CYInStorageShoppingOverviewBean.ItemBean.ItemListBean> receiveInStorageList = new ArrayList<>();
        List<CYInStorageShoppingOverviewBean.ItemBean.ItemListBean> allReceiveInStorageList = getInStorageShoppingOverviewBean(context).getBody().getItem_list();
        for (int i = 0; i < allReceiveInStorageList.size(); i++) {
            CYInStorageShoppingOverviewBean.ItemBean.ItemListBean item = allReceiveInStorageList.get(i);
            if (item.getMat_code().contains(materiel) || item.getMat_name().contains(materiel)) {
                receiveInStorageList.add(item);
                continue;
            }
        }
        return receiveInStorageList;
    }

    //通过批次获取itemId
    public static String getItemIdByBatch (Context context , String batch) {
        String itemId  = null;
        CYInStorageShoppingOverviewBean bean = getInStorageShoppingOverviewBean(context);
        List<CYInStorageShoppingOverviewBean.ItemBean.ItemListBean> list = bean.getBody().getItem_list();
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getBatch().equals(batch)) {
                itemId = list.get(i).getItem_id();
                break;
            }
        }
        return itemId;
    }
    //通过itemId获取物料详情
    public static CYInStorageShoppingOverviewBean.ItemBean.ItemListBean getDetailByItemId (Context context , String itemId) {
        CYInStorageShoppingOverviewBean.ItemBean.ItemListBean itemBean= new CYInStorageShoppingOverviewBean.ItemBean.ItemListBean();
        CYInStorageShoppingOverviewBean bean = getInStorageShoppingOverviewBean(context);
        List<CYInStorageShoppingOverviewBean.ItemBean.ItemListBean> list = bean.getBody().getItem_list();
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getItem_id().equals(itemId)) {
                itemBean = list.get(i);
                break;
            }
        }
         return itemBean;
    }

    //拼接校验仓位ean
    public static CYInStorageCheckPositionRequestBean getAllocatingGetListRequestBean (String locationId , String position) {
        CYInStorageCheckPositionRequestBean bean = new CYInStorageCheckPositionRequestBean();
        bean.setArea_position_code(position);
        bean.setLocation_id(locationId);
        return bean;
    }

    //判断新添加的批次是否已经存在
    public static boolean havePosition (List<CYInStoragePositionInformationBean.PositionBean> list , String position) {
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getPositionCode().equals(position)) {
                return true;
            }
        }
        return false;
    }

    //重新给仓位排序并保存
    public static void sortingPosition (Context context , List<CYInStoragePositionInformationBean.PositionBean> list , String itemId) {
        List<CYInStoragePositionInformationBean.PositionBean> saveList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            CYInStoragePositionInformationBean.PositionBean bean = list.get(i);
            if (!TextUtils.isEmpty(bean.getInStorageNumber()) && Float.parseFloat(bean.getInStorageNumber()) != 0) {
                bean.setPositionViewId(i);
                saveList.add(bean);
            }
        }
        CYInStorageShoppingOverviewBean overviewBean = getInStorageShoppingOverviewBean(context);
        List<CYInStorageShoppingOverviewBean.ItemBean.ItemListBean> itemBeanList = overviewBean.getBody().getItem_list();
        for (int i = 0; i < itemBeanList.size(); i++) {
            if (itemBeanList.get(i).getItem_id().equals(itemId)) {
                itemBeanList.get(i).setPositionBeanList(saveList);
                break;
            }
        }
        overviewBean.getBody().setItem_list(itemBeanList);
        saveInStorageShoppingOverViewBean(context , overviewBean);
    }

    //拼接采购入库过账提交bean
    public static CYInStorageShoppingConfirmRequestBean getInStorageShoppingConfirmRequestBean (Context context) {
        CYInStorageShoppingConfirmRequestBean bean = new CYInStorageShoppingConfirmRequestBean();
        CYInStorageShoppingOverviewBean overviewBean = getInStorageShoppingOverviewBean(context);
        bean.setStock_input_id(overviewBean.getBody().getStock_input_id());
        List<CYInStorageShoppingConfirmRequestBean.ItemListBean> itemListBeanList = new ArrayList<>();
        for (int i = 0; i < overviewBean.getBody().getItem_list().size(); i++) {
            CYInStorageShoppingConfirmRequestBean.ItemListBean itemListBean = new CYInStorageShoppingConfirmRequestBean.ItemListBean();
            CYInStorageShoppingOverviewBean.ItemBean.ItemListBean itemBean = overviewBean.getBody().getItem_list().get(i);
            itemListBean.setItem_id(itemBean.getItem_id());
            if (itemBean.getPositionBeanList() != null &&itemBean.getPositionBeanList().size() != 0) {
                List<CYInStorageShoppingConfirmRequestBean.ItemListBean.StockPositionListBean> stockPositionList = new ArrayList<>();
                for (int j = 0; j < itemBean.getPositionBeanList().size(); j++) {
                    CYInStorageShoppingConfirmRequestBean.ItemListBean.StockPositionListBean positionListBean = new CYInStorageShoppingConfirmRequestBean.ItemListBean.StockPositionListBean();
                    positionListBean.setArea_id(itemBean.getPositionBeanList().get(j).getArea_id());
                    positionListBean.setPosition_id(itemBean.getPositionBeanList().get(j).getPosition_id());
                    positionListBean.setWh_id(itemBean.getPositionBeanList().get(j).getWh_id());
                    positionListBean.setQty(itemBean.getPositionBeanList().get(j).getInStorageNumber());
                    stockPositionList.add(positionListBean);
                }
                itemListBean.setStock_position_list(stockPositionList);
            }
            itemListBeanList.add(itemListBean);
        }
        bean.setItem_list(itemListBeanList);
        return bean;

    }


    //根据状态过滤生产入库单
    public static List<CYInStorageProductionListBean.OrderBean> getProductionList (List<CYInStorageProductionListBean.OrderBean> list , String status) {
        List<CYInStorageProductionListBean.OrderBean> orderBeanList = new ArrayList<>();
        if (status.equals(CYInStorageProductionListActivity.PRODUCTION_COMPLETE)) {
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).getStatus().equals("3")) {//生产完成状态
                    orderBeanList.add(list.get(i));
                }
            }
        }else {
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).getStatus().equals("0")) {//未入库状态
                    orderBeanList.add(list.get(i));
                }
            }
        }
        return orderBeanList;
    }

    //过滤生产入库货品列表信息
    public static List<CYInStorageProductionOverviewBean.OverViewBean.ItemListBean> getProductionInStorageList(Context context, String materiel) {
        List<CYInStorageProductionOverviewBean.OverViewBean.ItemListBean> receiveInStorageList = new ArrayList<>();
        List<CYInStorageProductionOverviewBean.OverViewBean.ItemListBean> allReceiveInStorageList = getInStorageProductionOverviewBean(context).getBody().getItem_list();
        for (int i = 0; i < allReceiveInStorageList.size(); i++) {
            CYInStorageProductionOverviewBean.OverViewBean.ItemListBean item = allReceiveInStorageList.get(i);
            if (item.getMat_code().contains(materiel) || item.getMat_name().contains(materiel)) {
                receiveInStorageList.add(item);
                continue;
            }
        }
        return receiveInStorageList;
    }

    //通过物料id获取物料详情
    public static CYInStorageProductionOverviewBean.OverViewBean.ItemListBean getProductionMaterialDetail(Context context, String matId) {
        CYInStorageProductionOverviewBean.OverViewBean.ItemListBean bean = new CYInStorageProductionOverviewBean.OverViewBean.ItemListBean();
        List<CYInStorageProductionOverviewBean.OverViewBean.ItemListBean> allReceiveInStorageList = getInStorageProductionOverviewBean(context).getBody().getItem_list();
        for (int i = 0; i < allReceiveInStorageList.size(); i++) {
            CYInStorageProductionOverviewBean.OverViewBean.ItemListBean item = allReceiveInStorageList.get(i);
            if (item.getMat_id().equals(matId)) {
                bean = allReceiveInStorageList.get(i);
                break;
            }
        }
        return bean;
    }

    //获取需要校验的打包码
    public static List<CYInStorageStringBean> getPackagingCodelist (Context context) {
        CYInStorageProductionOverviewBean bean = getInStorageProductionOverviewBean(context);
        return bean.getBody().getPackagingCodelist();
    }

    //更新生产完成状态物料行项目序列号打包码信息
    public static void updateProductionInformation (Context context , List<SNBean.SNInfoBean> list , List<CYInStorageStringBean> packageList ,  List<SNBean.SNInfoBean.SnListBean> SNCodeList , String matId , String number) {
        CYInStorageProductionOverviewBean overviewBean = getInStorageProductionOverviewBean(context);
        overviewBean.getBody().setPackagingCodelist(packageList);
        List<CYInStorageProductionOverviewBean.OverViewBean.ItemListBean> itemListBeanList = overviewBean.getBody().getItem_list();
        for (int i = 0; i < itemListBeanList.size(); i++) {
            CYInStorageProductionOverviewBean.OverViewBean.ItemListBean item = itemListBeanList.get(i);
            if (item.getMat_id().equals(matId)) {
                item.setNew_stock_position_list(list);
                item.setSerialNumberlist(SNCodeList);
                item.setInStorageNumber(number);
                itemListBeanList.set(i , item);
                break;
            }
        }
        overviewBean.getBody().setItem_list(itemListBeanList);
        saveInStorageProductionOverViewBean(context , overviewBean);

    }

    //更新生产完成状态物料行项目序列号打包码信息
    public static void updateNoInStorageInformation (Context context , List<SNBean.SNInfoBean> list , List<CYInStorageStringBean> packageList ,  List<SNBean.SNInfoBean.SnListBean> SNCodeList , String matId , String number) {
        CYInStorageProductionOverviewBean overviewBean = getInStorageProductionOverviewBean(context);
//        overviewBean.getBody().setPackagingCodelist(packageList);
        List<CYInStorageProductionOverviewBean.OverViewBean.ItemListBean> itemListBeanList = overviewBean.getBody().getItem_list();
        for (int i = 0; i < itemListBeanList.size(); i++) {
            CYInStorageProductionOverviewBean.OverViewBean.ItemListBean item = itemListBeanList.get(i);
            if (item.getMat_id().equals(matId)) {
                item.setNew_stock_position_list(list);
                item.setSerialNumberlist(SNCodeList);
                item.setInStorageNumber(number);
                item.setPackagingCodelist(packageList);
                itemListBeanList.set(i , item);
                break;
            }
        }
        overviewBean.getBody().setItem_list(itemListBeanList);
        saveInStorageProductionOverViewBean(context , overviewBean);

    }
    //过滤打包码并保存
    public static List<CYInStorageStringBean> getPackagingCodelists (Context context , List<CYInStorageProductionOverviewBean.OverViewBean.ItemListBean.StockPositionListBean> list , String matId) {
        List<CYInStorageStringBean> stringBeanList = new ArrayList<>();
        CYInStorageProductionOverviewBean bean = getInStorageProductionOverviewBean(context);
        List<CYInStorageProductionOverviewBean.OverViewBean.ItemListBean> listBeanList = bean.getBody().getItem_list();
        if (list != null && list.size() != 0) {
            for (int i = 0; i < list.size(); i++) {
                LogUtils.i("pgcode1 ==== "  + list.get(i).getPackage_code());
                CYInStorageStringBean stringBean = new CYInStorageStringBean();
                stringBean.setId(list.get(i).getPackage_id());
                stringBean.setCode(list.get(i).getPackage_code());
                stringBeanList.add(stringBean);
            }
        }
        //去重
        if (stringBeanList.size() != 0) {
            if (stringBeanList != null && stringBeanList.size() != 0) {
                for (int i = 0; i < stringBeanList.size(); i++) {
                    for (int j = stringBeanList.size() - 1; j > i ; j--) {
                        if (stringBeanList.get(i).getCode().equals(stringBeanList.get(j).getCode())) {
                            stringBeanList.remove(j);
                        }
                    }
                }
            }
        }
        for (int i = 0; i < stringBeanList.size(); i++) {
            LogUtils.i("pgcode2 ==== "  + stringBeanList.get(i).getCode());
        }
        for (int i = 0; i < listBeanList.size(); i++) {
            if (listBeanList.get(i).getMat_id().equals(matId)) {
                listBeanList.get(i).setPackagingCodelist(stringBeanList);
            }
        }
        bean.getBody().setItem_list(listBeanList);
        saveInStorageProductionOverViewBean(context , bean);
        return stringBeanList;
    }

    //过滤序列号并保存
    public static List<SNBean.SNInfoBean.SnListBean> getSNCodelist (Context context , List<CYInStorageProductionOverviewBean.OverViewBean.ItemListBean.StockPositionListBean> list , String matId) {
        List<SNBean.SNInfoBean.SnListBean> stringBeanList = new ArrayList<>();
        CYInStorageProductionOverviewBean bean = getInStorageProductionOverviewBean(context);
        List<CYInStorageProductionOverviewBean.OverViewBean.ItemListBean> listBeanList = bean.getBody().getItem_list();
        if (list != null && list.size() != 0) {
            for (int i = 0; i < list.size(); i++) {
                LogUtils.i("setSn_code =======" + list.get(i).getSn_code() + "setSn_id ======= " + list.get(i).getSn_id());
                SNBean.SNInfoBean.SnListBean stringBean = new SNBean.SNInfoBean.SnListBean();
                stringBean.setSn_id(list.get(i).getSn_id());
                stringBean.setSn_code(list.get(i).getSn_code());
                stringBeanList.add(stringBean);
            }
        }
        //去重
//        if (stringBeanList.size() != 0) {
//            if (stringBeanList != null && stringBeanList.size() != 0) {
//                for (int i = 0; i < list.size(); i++) {
//                    for (int j = list.size() - 1; j > i ; j--) {
//                        if (stringBeanList.get(i).getCode().equals(stringBeanList.get(j).getCode())) {
//                            stringBeanList.remove(j);
//                        }
//                    }
//                }
//            }
//        }
        for (int i = 0; i < listBeanList.size(); i++) {
            if (listBeanList.get(i).getMat_id().equals(matId)) {
                listBeanList.get(i).setSerialNumberlist(stringBeanList);
            }
        }
        bean.getBody().setItem_list(listBeanList);
        saveInStorageProductionOverViewBean(context , bean);
        return stringBeanList;
    }

    //拼接校验打包码和序列号请求bean
    public static CYInStorageCheckSNCodeRequestBean getCheckSNCodeBean (String condition  , String id) {
        CYInStorageCheckSNCodeRequestBean bean = new CYInStorageCheckSNCodeRequestBean();
        bean.setCondition(condition);
        bean.setStock_input_id(id);
        return bean;
    }


    //通过物料id个打包码获取打包码中的序列号
    public static List<SNBean.SNInfoBean.SnListBean> getSNCodeByPackagingCode (List<SNBean.SNInfoBean> list , String packagingCode) {
        List<SNBean.SNInfoBean.SnListBean> snListBeansList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getPackage_code().equals(packagingCode)) {
                snListBeansList = list.get(i).getSn_list();
                break;
            }
        }
        return snListBeansList;
    }


    public static List<SNItemInfo> getPackageDetail(List<SNBean.SNInfoBean> list , String packagingCode) {
        List<SNBean.SNInfoBean.SnListBean> snItemList = getSNCodeByPackagingCode(list , packagingCode);
        List<SNItemInfo> result = new ArrayList<>();
        for (int i = 0; i < snItemList.size(); i++) {
            result.add(new SNItemInfo(snItemList.get(i).getSn_id(), snItemList.get(i).getSn_code()));
        }
        return result;
    }

    //拼接生产入库提交bean
    public static CYInStorageProductionSubmitRequestBean getProductionInStorageSubmitBean (Context context) {
        CYInStorageProductionSubmitRequestBean bean = new CYInStorageProductionSubmitRequestBean();
        CYInStorageProductionOverviewBean overviewBean = getInStorageProductionOverviewBean(context);
        bean.setStock_input_code(overviewBean.getBody().getStock_input_code());
        bean.setStock_input_id(overviewBean.getBody().getStock_input_id());
        List<CYInStorageProductionSubmitRequestBean.ItemListBean> itemList = new ArrayList<>();
        for (int i = 0; i < overviewBean.getBody().getItem_list().get(0).getNew_stock_position_list().size(); i++) {
            LogUtils.i("packageCode ===== " + overviewBean.getBody().getItem_list().get(0).getNew_stock_position_list().get(i).getPackage_code());
        }
        for (int i = 0; i < overviewBean.getBody().getItem_list().size(); i++) {
            CYInStorageProductionSubmitRequestBean.ItemListBean itemListBean = new CYInStorageProductionSubmitRequestBean.ItemListBean();
            itemListBean.setItem_id(overviewBean.getBody().getItem_list().get(i).getItem_id());
            List<CYInStorageProductionSubmitRequestBean.ItemListBean.StockPositionListBean> stockPositionListBeans = new ArrayList<>();
            List<SNBean.SNInfoBean> newStockList = overviewBean.getBody().getItem_list().get(i).getNew_stock_position_list();
            for (int j = 0; j < newStockList.size(); j++) {
                for (int k = 0; k < newStockList.get(j).getSn_list().size(); k++) {
                    CYInStorageProductionSubmitRequestBean.ItemListBean.StockPositionListBean stockPositionListBean = new CYInStorageProductionSubmitRequestBean.ItemListBean.StockPositionListBean();
                    if (!TextUtils.isEmpty(newStockList.get(j).getPackage_id())) {
                        stockPositionListBean.setPackage_id(newStockList.get(j).getPackage_id());
                    }
                    stockPositionListBean.setSn_id(newStockList.get(j).getSn_list().get(k).getSn_id());
                    stockPositionListBean.setQty("1");
                    stockPositionListBeans.add(stockPositionListBean);
                }

            }
            itemListBean.setStock_position_list(stockPositionListBeans);
            itemListBean.setQty(overviewBean.getBody().getItem_list().get(i).getQty());
            itemList.add(itemListBean);
        }
        bean.setItem_list(itemList);
        return bean;
    }

    //判断生产入库所有行项目是否都填完

    public static boolean allItemIsDone (Context context) {
        CYInStorageProductionOverviewBean overviewBean = getInStorageProductionOverviewBean(context);
        for (int i = 0; i < overviewBean.getBody().getItem_list().size(); i++) {
            if (Float.parseFloat(overviewBean.getBody().getItem_list().get(i).getInStorageNumber()) != Float.parseFloat(overviewBean.getBody().getItem_list().get(i).getQty())) {
                Utils.middleToast(context , "第" + (i + 1) + "个行项目打包数量不等于生产数量，不能提交");
                return false;
            }
        }
        return true;
    }
}
